﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebProjectOrder.WebServices;

namespace WebProjectOrder.BusinessLayer
{
    public class ConfigurationManager
    {
        #region Atributos

        private List<Tax> _Taxes;
        private bool _IsError;
        private String _ErrorMessage;
        public AuxiliarAccount AccountSelected =  new AuxiliarAccount();
        #endregion

        #region Properties
        public bool IsError
        {
            get
            {
                return _IsError;
            }
        }

        public String ErrorMessage
        {
            get
            {
                return _ErrorMessage;
            }
        }
        #endregion

        #region Singleton
        private ConfigurationManager() 
        {
            _IsError = false;
            _ErrorMessage = "";
            _Taxes = WebServices.WebServices.getInstance().GetTaxes();
            if (_Taxes == null)
            {
                _IsError = true;
                _ErrorMessage = Constants.ERROR_IMPUESTOS_READING;
            }
            else { _IsError = false; }
        }

        /// <summary>
        /// Unica Instancia de la Clase
        /// </summary>
        private static ConfigurationManager _instance;
        /// <summary>
        /// Método para implementar el patrón singlenton
        /// </summary>
        public static ConfigurationManager GetInstance() 
        {
            if (_instance == null)
                _instance = new ConfigurationManager();
            return _instance;
        }

        #endregion

        #region Métodos

        /// <summary>
        /// Método que retorna la lista de impuestos
        /// </summary>
        /// <returns></returns>
        public List<Tax> GetTaxes() 
        {
            if (_Taxes == null) 
            {
                _IsError = true;
                _ErrorMessage = Constants.ERROR_IMPUESTOS_READING;
            }
            return _Taxes;
        }

        #endregion

    }
}